/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package parse;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import learn.LexicalEntry;
import learn.Lexicon;

/**
 *
 * @author phong
 */
public class Parser {
    
    Chart chart;
    String[] tokens;
    Lexicon lexicon;
    
    public Parser(String sen, Lexicon lexicon) {
        tokens = util.Util.tokenize(sen, " ");
        chart = null;
        this.lexicon = lexicon;
    }
    
    public void parse(CCGDerivation der) {
        chart = new Chart(tokens.length);
        
        Chart derChart = new Chart(tokens.length);
        der.putInChart(derChart);
        
        // lexical nodes
        List<CCGLexNode> lexNodes = der.getLexNodes();
        for (CCGLexNode lnode : lexNodes) {
            int itok = lnode.tokStartId;
            List<LexicalEntry> les = lexicon.getLexEntries(lnode.getLexSurface());
            Cell cell = chart.getCell(itok, itok);
            
            for (LexicalEntry le : les) {
                double score = lexicon.getScore(le);
                CCGLexNode node = new CCGLexNode(le.getLexSurf(), le.getSem(), itok, score);
                cell.add(node);
            }
        }
        
        // internal nodes
        for (int len = 2; len <= tokens.length; len++) {
            for (int i = 0; i <= tokens.length - len; i++) {
                int j = i + len - 1;
                Cell cell = chart.getCell(i, j);
                for (CCGNode dnode : derChart.getCell(i, j).getCCGNodes()) {
                    CCGNode[] children = new CCGNode[dnode.getChildren().length];
                    for (CCGNode dchild : dnode.getChildren()) {
                        
                    }
                }
            }
        }
    }
}
